$(function(){
	getNoticeList();
	getUserInfo();
	$('#search').bind('keypress',function(event){ 
        if(event.keyCode == 13){  
        	window.location.href=ctp+'/web/search.jsp?keyword='+$('#search').val();
        }  

    });
});

function search(){
	window.location.href=ctp+'/web/search.jsp?keyword='+$('#search').val();
}

function getUserInfo(){
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/userInfo',
			success:function(data){
				if(data.code==200){
					if(data.data.pic==''){
						$("#user_head_pic").attr("src","/images/nopic.jpg");
					}else{
						$("#user_head_pic").attr("src",data.data.pic);
					}

				}
			},
			error:function(data){
			}
	    });
}


//获取通知数量
function getNoticeList(){
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/getNoticeList',
			success:function(data){
				//console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
						var type="";
						var reson=""
						if(data.data[i].notice_type==0){
							type="加入班组申请";
							reason=data.data[i].user_name+" 申请加入班组，理由："+data.data[i].reason;
							result+=' <li><a href="javascript:;">';
							result+=' <div><i class="fa fa-envelope fa-fw"></i> ';
							result+= reason+'</div></a></li>';
							result+='<div><button class="btn btn-sm btn-primary pull-right m-t-n-xs" onclick="checkMessage(1,'+data.data[i].id+')" style="margin-left:5px" type="button">同意</button><button class="btn btn-sm btn-primary pull-right m-t-n-xs" style="margin-left:5px"  onclick="checkMessage(2,'+data.data[i].id+')" type="button">拒绝</button><button class="btn btn-sm btn-primary pull-right m-t-n-xs" style="margin-left:5px"  onclick="checkMessage(3,'+data.data[i].id+')" type="button">忽略</button></div>';
						}else if(data.data[i].notice_type==1){
							type="同意邀请";
						}else if(data.data[i].notice_type==3){
							type="新的话题";
							reason=data.data[i].user_name+" 发布新的话题："+data.data[i].topic_title;
							result+=' <li><a href="javascript:;">';
							result+=' <div><i class="fa fa-envelope fa-fw"></i> ';
							result+= reason+'</div></a></li>';
							result+='<div><button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="button">点击查看</button></div>';
							
						}
					}
					$('#message_content').append(result);
					$('#notice_num').html(data.data.length);
				}
			},
			error:function(data){
			}
	    });
	 
	
}

function showAlt(){
	$("#message_content").toggle();
}

function checkMessage(Type,id){
	 art.dialog("确定？", function(){
		 $.ajax({
				type : 'POST',
				dataType:'json', 
				url : ctp + '/interface/classMemberAddCheck',
				data: {
					notice_id:id, 
					type: Type //1 同意 2 拒绝 3忽略
				},
				success:function(data){
					//console.log(JSON.stringify(data.data));
					if(data.code==200){
						getNoticeList();
					}
				},
				error:function(data){
				}
		    });
	 },function(){
		 
	 });
	 
	 
	 
}